package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyFileBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.MediaUtil;
import stark.common.basic.utils.TimeUtil;

public class CreationRecordAdapter extends StkProviderMultiAdapter<MyFileBean> {

    public CreationRecordAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(70));
        addItemProvider(new CreationRecordProvider());
    }

    private int type;

    public void setType(int type) {
        this.type = type;
    }

    private class CreationRecordProvider extends BaseItemProvider<MyFileBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_creation_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyFileBean bean) {
            if (type == 2) {
                baseViewHolder.getView(R.id.llCreationRecordItemAudio).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.ivCreationRecordItemBg).setVisibility(View.VISIBLE);
                if (bean.isSelect()){
                    baseViewHolder.setImageResource(R.id.ivCreationRecordItemAudio,R.drawable.ayinpinbofangz);
                }else {
                    baseViewHolder.setImageResource(R.id.ivCreationRecordItemAudio,R.drawable.ayinpin);
                }
            } else {
                baseViewHolder.getView(R.id.llCreationRecordItemAudio).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.ivCreationRecordItemBg).setVisibility(View.GONE);
                Glide.with(getContext()).load(bean.getUrl()).into((ImageView) baseViewHolder.getView(R.id.ivCreationRecordItemImg));
            }
            if (type == 0) {
                baseViewHolder.getView(R.id.tvCreationRecordItemDuration).setVisibility(View.GONE);
            } else {
                baseViewHolder.getView(R.id.tvCreationRecordItemDuration).setVisibility(View.VISIBLE);
                baseViewHolder.setText(R.id.tvCreationRecordItemDuration, TimeUtil.getMmss(MediaUtil.getDuration(bean.getUrl())));
            }
            baseViewHolder.setText(R.id.tvCreationRecordItemTime, TimeUtils.millis2String(FileUtils.getFileLastModified(bean.getUrl()), "MM-dd"));
            baseViewHolder.setText(R.id.tvCreationRecordItemSize, ConvertUtils.byte2FitMemorySize(FileUtils.getLength(bean.getUrl()), 2));
        }
    }
}
